package com.douyang.base.handle;

import com.douyang.base.expcetion.TradeException;
import com.douyang.base.expcetion.UserException;
import com.douyang.base.model.Result;
import com.douyang.base.expcetion.VideoException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class ExceptionHandle {

    @ExceptionHandler(VideoException.class)
    public Result<String> videoException(VideoException e) {
        log.error("video异常------------{}---------",e.getMessage());
        return Result.fail(e.getMessage());
    }

    @ExceptionHandler(TradeException.class)
    public Result<String> tradeException(TradeException e) {
        log.error("trade异常：------------{}---------",e.getMessage());
        return Result.fail(e.getMessage());
    }


    @ExceptionHandler(Exception.class)
    public Result<String> exception(Exception e) {
        log.error("未知异常------------{}---------",e.getMessage());
        return Result.fail(e.getMessage());
    }

    @ExceptionHandler(MethodArgumentNotValidException.class)
    public Result<String> methodArgumentNotValidException(MethodArgumentNotValidException e){
        log.error("传入参数异常----------------{}-------------",e.getMessage());
        return Result.fail(e.getMessage());
    }

    @ExceptionHandler(UserException.class)
    public Result<String>userException(UserException e) {
        log.error("user异常----------------{}-------------",e.getMessage());
        return Result.fail(e.getMessage());
    }
}
